package cz.mendelu.swi2.skladDilu;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cz.mendelu.swi2.skladDilu.interfaces.iWarehouse;



/**
 * Trida skladu slouzi pro uchovani zaznamu o vsech dostupnych dilech.
 * @author infsys
 * @version 1.0
 * @created 20-4-2012 12:47:56
 */

public class Warehouse implements iWarehouse, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Part> listOfParts = new ArrayList<Part>();

	//@Autowired
	public Warehouse(){
		prepareTestData();
	}
	



	/**
	 * 
	 * @param part
	 */
	public boolean addPart(Part part){
		try
		{
			listOfParts.add(part);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean removePart(Part part) {
		// TODO Auto-generated method stub
		try
		{
			listOfParts.remove(part);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public void updateInventoryStateOnProdukt(long uid,int count)
	{
		Part update = getPart(uid);
		update.setInventoryState(count);
	}

	/**
	 * 
	 * @param int
	 */
	public Part getPart(long id){
		for (Part part : listOfParts) {
			if(part.getUid()==id)
				return part;
		}
		return null;
	}

	public List<Part> getPartList(){
		return listOfParts;
	}

		public List<Part> getListOfParts() {
		return listOfParts;
	}

	public void setListOfParts(List<Part> listOfParts) {
		this.listOfParts = listOfParts;
	}

	public void prepareTestData() {
		
		listOfParts.add(new Part(0,"Nazev",10,"popisek 1"));
		listOfParts.add(new Part(1,"Nazev2",130,"popisek 2"));
		listOfParts.add(new Part(2,"Nazev3",120,"popisek 3"));
		listOfParts.add(new Part(3,"Nazev4",150,"popisek 4"));
		listOfParts.add(new Part(4,"Nazev5",160,"popisek 5"));
		listOfParts.add(new Part(5,"Nazev6",170,"popisek 6"));
		
	}

	

}